<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="狮偶">
    <meta name="keywords" content="狮偶">
    <meta name="author" content="奕尘">
    <title>狮偶-Sample</title>
    <link href="./css/index_2.css" rel="stylesheet">
    <script src="./js/jquery.min.js"></script>

</head>
<body>
    <nav>
      
        <ul>
            <li id="nav-logo">
                <a href="">
                    <img class="lion" src="./images/logo_white.svg" alt="狮偶logo">
                    <div>狮偶</div>      
                </a>         
            </li>
            <ul id="nav-manu"> 
                <li>
                    <a href="">社区</a>
                </li>
                <li>
                    <a href="">视频</a>
                </li>     
            </ul>

               
            
           
            
        </ul>
    </nav>

    <main>
        
        <div class="info">
            
        </div>
        <ul id="YClist"></ul>
    </main>
   
    <footer>
        <img>
    </footer>
        
    <script>
        function openProject(projPath) {
            let IDE_PATH = '../../openblock/';
            if (projPath.endsWith('json')) {
                let url =
                    IDE_PATH +
                    'frontpage/index.html#%7B%22proj%22:%22/testing/' +
                    projPath +
                    '%22%7D'
                window.open(url);
            } else if (projPath.endsWith('.zip') || projPath.endsWith('.obp')) {
                let url =
                    IDE_PATH +
                    'frontpage/index.html#%7B%22srczip%22:%22/testing/' +
                    projPath +
                    '%22%7D'
                window.open(url);
            }
        }

        function makeURL(projPath) {
            let IDE_PATH = '../../openblock/';
            if (projPath.endsWith('.json')) {
                let url =
                    IDE_PATH +
                    'frontpage/index.html#%7B%22proj%22:%22/testing/' +
                    projPath +
                    '%22%7D'
                return (url);
            } 
            else if (projPath.endsWith('.zip') || projPath.endsWith('.obp')) {
                let url =
                    IDE_PATH +
                    'frontpage/index.html#%7B%22srczip%22:%22/testing/' +
                    projPath +
                    '%22%7D'
                return (url);
            }
        }
            $(document).ready(function () {
                let htmlstr = "";
                let imgstr = '';
                let cloud = '<img class="YClist-img-cloud" src="./images/project.svg">';
                $.getJSON("./sample.json", function(result){
                    let txt = result;
                  
               for (let i in txt) {

                    let title = txt[i].title
                    let project = txt[i].project


                    for (let j in project) {
                        let sort = 0
                         sort = i+1  //file start from 1
                        let BaseUrl = 'sample/'+ sort +'/'+ project[j].name +'/'
                        let Path = BaseUrl + project[j].name +'.obp'
                        let ImgUrl

                        if (project[j]['img']) {

                            ImgUrl = '../'+BaseUrl +project[j]['img']
                            imgstr = '<img src="' + ImgUrl + '" class="YClist-img" >';
                        } else {
                    
                            imgstr = '<img class="YClist-img" src="./images/nothing.svg">';
                        }
                        htmlstr += '<li><a target="_Blank" href="' + makeURL(Path) + '"><div>' + project[j].name + title +'</div>' + cloud + '' + imgstr + '</a></li>';

               
                    }
            

                    $('#YClist').html(htmlstr);
                    $(window).scroll(function () {
                        var $scroll = $(document).scrollTop()
                        if ($scroll > 30) {
                            $(".scrollTo").css('display', '');
                        } else {
                            $(".scrollTo").css('display', 'none');
                        }

                    });
                    $('.scrollTo').click(function () {
                        scrollTo(0, 0);
                    })
                }

                
            })
            //console.log(txt);
            
           
    })
    
    


    </script>
</body>
</html>